interface dataSourceType {
  [propName: string]: any;
}
const email = (_rule: dataSourceType, value: string, callback: () => {}, type = 'email', msg: '邮箱格式不正确', useValue: number = 0) => {
  if (_rule.required) {// 必填项验证非空并排除非必须项
    if (!useValue) { // 使用fullField校验
      if ((value === '' || value === null || value === undefined)) {
        return Promise.reject(`此项必填`);
      } else {
        const reg = /^[a-zA-Z0-9][a-zA-Z0-9 . _-]+(@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+)$/;
        return reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${'邮箱格式不正确'}`) : Promise.reject(`${_rule.msg2}`);
      }
    } else {
      if (!value || value == undefined) {
        return Promise.reject(`${_rule.msg1}`);
      } else {
        const reg = /^[a-zA-Z0-9][a-zA-Z0-9 . _-]+(@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+)$/;
        return reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${msg}`) : Promise.reject(`${_rule.msg2}`);
      }
    }
  } else {

    if (!useValue) {
      console.log(2323, value, _rule.fullField)
      if ((value === '' || value === null || value === undefined)) {
        return Promise.resolve();
      } else {
        const reg = /^[a-zA-Z0-9][a-zA-Z0-9 . _-]+(@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+)$/;
        return reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${'邮箱格式不正确'}`) : Promise.reject(`${_rule.msg2}`);
      }
    } else {
      if (!value || value == undefined) {
        return Promise.resolve();
      } else {
        const reg = /^[a-zA-Z0-9][a-zA-Z0-9 . _-]+(@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+)$/;
        return reg.test(value) ? Promise.resolve() : msg ? Promise.reject(`${'邮箱格式不正确'}`) : Promise.reject(`${_rule.msg2}`);
      }
    }
  }
}
export default {
  component: {//展示型组件信息，每个组件的信息各不相同
    componentName: 'email', // 组件名称
    settings: {// 对应的设置项， 可能不同组件设置也不尽相同。
      value: '',
      placeholder: '请输入',
      param: 'email',
      rule: {
        required: false,
        validator: email,
        trigger: ["blur"],
        msg1: '邮箱格式不正确！',
        msg2: '邮箱格式不正确！',
        api: "fetchOssNameUnique",
        key: 'siteDomain',
        params: {}, //校验传参
      },
      label: "邮箱:",
      beforeText: '',
      afterText: '',
      api: "fetchOssNameUnique",
      width: 492,
      showCount: false,
      maxCount: 25,
      marginLeft: 32,
      marginTop: 0,
      helpMsg: '',
      type: 'textInput',
      associated: '',
      associatedValue: '',
    },
  }
}